<?php
declare(strict_types=1);

namespace App\Controller\Admin;

use App\Service\PermissionService;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use App\Service\AdminService;
use Psr\Http\Message\ResponseInterface;

class IndexController extends AbstractController
{
    /**
     * @Inject
     * @var AdminService
     */
    protected $adminService;

	/**
	 * @Inject
	 * @var PermissionService
	 */
    protected $permissionService;

	/**
	 * 后台主页
	 * @return ResponseInterface
	 */
	public function index()
	{
		$admin = $this->adminService->queryById($this->session->get('admin_id'));
		return $this->render->render('admin/index/index.twig', [
		    'admin' => $admin
        ]);
	}

	public function welcome()
	{
		return $this->render->render('admin/index/welcome.twig');
	}

	/**
	 * 初始化
	 * @return ResponseInterface
	 */
	public function initUrl()
	{
		$menus = $this->permissionService->queryMenus();
		return $this->response->json([
			"homeInfo" => [
				"title" => "首页",
				"href" => "/admin/welcome",
			],
			"logoInfo" => [
				"title" => "LAYUI MINI",
				"image" => "/images/logo.png",
				"href" => "",
			],
			"menuInfo" => $menus,
		]);
	}

	public function clear()
	{
		return $this->response->json([
			'code' => 1,
			'msg' => '服务端清理缓存成功',
		]);
	}
}